﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMSUIMVC.Aubit.Sales;
using WMSUIMVC.DTO.Client;
using WMSUIMVC.DTO.Injure;
using WMSUIMVC.DTO.Movelibrary;
using WMSUIMVC.DTO.Unit;
using XuanKeZz.Application.HTTP;

namespace WMSUIMVC.Controllers
{
    public class MovelibraryController : Controller
    {
        protected readonly IConfiguration _configuration;

        public MovelibraryController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 移库显示页面
        /// </summary>
        /// <returns></returns>
        public IActionResult ShowMovelibrary()
        {
            return View();
        }

        /// <summary>
        /// 客户显示
        /// </summary>
        /// <param name="showclient"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetMovelibraryShow(SelMovelibraryDTO showmovelibrary)
        {
            HttpClientWrapper client = new HttpClientWrapper(showmovelibrary.Token);
            string url = _configuration["Url"] + "ckd/api/MovelibraryRead/GetMovelibrary?MovelibraryCode=" + showmovelibrary.MovelibraryCode + "&MovelibraryType=" + showmovelibrary.MovelibraryType + "&DocumentStatus=" + showmovelibrary.DocumentStatus + "&Office_Id=" + showmovelibrary.Office_id + "&PageIndex=" + showmovelibrary.PageIndex + "&PageSize=" + showmovelibrary.PageSize;
            string GetClient = await client.GetAsync(url);
            return Json(GetClient);
        }
        /// <summary>
        /// 移库新增页面
        /// </summary>
        /// <returns></returns>
        public IActionResult AddMovelibrary()
        {
            return View();
        }
        /// <summary>
        /// 添加移库信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddMovelibrarys(AddMovelibraryDTO obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string list = JsonConvert.SerializeObject(obj);
            string url = _configuration["Url"] + "ckx/api/Movelibrary/AddMovelirary";
            string res = await client.PostAsync(url, list);
            return Json(res);
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="delmovelibrary"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> DelAllMovelibrary(DelMovelibraryDTO delmovelibrary)
        {
            HttpClientWrapper client = new HttpClientWrapper(delmovelibrary.Token);
            string url = _configuration["Url"] + "ckx/api/Movelibrary/DelMovelibrary";
            string list = JsonConvert.SerializeObject(delmovelibrary);
            var res = await client.PostAsync(url, list);
            return Json(res);
        }
        /// <summary>
        /// 反填
        /// </summary>
        /// <param name="unit"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetMovelibraryFt(FanMovelibraryDTO fmovelibrary)
        {
            HttpClientWrapper client = new HttpClientWrapper(fmovelibrary.Token);
            string url = _configuration["Url"] + "ckd/api/MovelibraryRead/GetMovelibraryById?MovelibraryId=" + fmovelibrary.MovelibraryId;
            string GetUnit = await client.GetAsync(url);
            return Json(GetUnit);
        }
        /// <summary>
        /// 修改新增页面
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdMovelibrary()
        {
            return View();
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public async Task<IActionResult> UpdMovelibrar(UpdMovelibraryDTO obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = _configuration["Url"] + "ckx/api/Movelibrary/UpdMovelibrary";
            string list = JsonConvert.SerializeObject(obj);
            string UpdMovelibrary = await client.PostAsync(url, list);
            return Json(UpdMovelibrary);
        }
        /// <summary>
        /// 审核移库管理
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> AuditMovelibrary(AuditMovelibraryDTO obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = _configuration["Url"] + "ckx/api/Movelibrary/UpdStateMovelibrary?DocumentStatus=" + obj.DocumentStatus + "&ReasonForReview=" + obj.ReasonForReview + "&MovelibraryId=" + obj.MovelibraryId + "&office_id=" + obj.office_id + "&user_id=" + obj.user_id;
            string list = JsonConvert.SerializeObject(obj);
            string res = await client.PostAsync(url, list);
            return Json(res);
        }
    }
}
